package ift605.EquationWithTrainingAgents.agent;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import ift605.EquationWithTrainingAgents.behavior.common.VerificationBehavior;
import ift605.EquationWithTrainingAgents.struct.DerivationInfo;
import ift605.EquationWithTrainingAgents.struct.LearningMessage;
import ift605.EquationWithTrainingAgents.struct.PendingRequest;
import jade.core.Agent;
import jade.core.behaviours.Behaviour;
import jade.core.behaviours.CyclicBehaviour;
import jade.domain.DFService;
import jade.domain.FIPAException;
import jade.domain.FIPAAgentManagement.DFAgentDescription;
import jade.domain.FIPAAgentManagement.ServiceDescription;
import jade.lang.acl.ACLMessage;
import jade.lang.acl.MessageTemplate;
import jade.lang.acl.UnreadableException;

public class ComplexPoolAgent extends PoolAgent{
	public static final String COMPLEX_POOL_AGENT_DF = "ComplexPoolAgent";
	
	@Override
	public void setup()
	{
		//super.setup();
		try {
			mInvalidRequest = new ArrayList<Integer>();
			//mKnownDerivation = new HashMap<String, List<AID>>();
			mInProgess = new HashMap<String, DerivationInfo>();
			mEquationChunk = new HashMap<Integer, List<PendingRequest>>();
			
			//Register the agent to the DIRECTORY FOLDER
			DFAgentDescription dfd = new DFAgentDescription();
			dfd.setName(getAID());
			ServiceDescription sd = new ServiceDescription();
			sd.setType(COMPLEX_POOL_AGENT_DF);
			sd.setName(COMPLEX_POOL_AGENT_DF);
			
			dfd.addServices(sd);
			DFService.register(this, dfd);
		} catch (FIPAException e) {
			e.printStackTrace();
		}
		
		//addBehaviour(new RegisteringBehavior());
		addBehaviour(new VerificationBehavior());
		addBehaviour(new UpdateInvalidRequestRangeBehaviour());
		
		Object[] obj = getArguments();
		
		if(obj.length > 1)
		{
			addBehaviour((Behaviour)obj[0]);
			addBehaviour((Behaviour)obj[1]);
		}
	}
}
